package com.tanhua.api.impl.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.api.db.SoulStandardApi;
import com.tanhua.domain.db.SoulStandard;
import com.tanhua.mapper.db.SoulScoreMapper;
import com.tanhua.mapper.db.SoulStandardMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Richard Wang
 * @date 2021/9/5 20:16
 */
@Service
public class SoulStandardApiImpl implements SoulStandardApi {
    @Autowired
    private SoulStandardMapper soulStandardMapper;
    @Override
    public Integer findStandardId(Integer score) {
        QueryWrapper<SoulStandard> qr = new QueryWrapper<>();
        //选择小于当前分数的
        qr.lt("score",score);
        //按照降序排列
        qr.orderByDesc("score");
        //获取所有小于当前得分的所有集合
        List<SoulStandard> list = soulStandardMapper.selectList(qr);
        //选择在小于当前得分的score中最接近的
        SoulStandard soulStandard = list.get(0);

        return soulStandard.getId();
    }

    @Override
    public SoulStandard findSoulStandard(Integer standardId) {
        SoulStandard soulStandard = soulStandardMapper.selectById(standardId);
        return soulStandard;
    }
}
